package cn.percent.test;

import cn.percent.dao.IUserDao;
import cn.percent.io.Resources;
import cn.percent.parse.XMLCacheParse;
import cn.percent.pojo.User;
import cn.percent.sqlSession.SqlSession;
import cn.percent.sqlSession.SqlSessionFactory;
import cn.percent.sqlSession.SqlSessionFactoryBuilder;
import cn.percent.utils.ArrayUtil;
import cn.percent.utils.DBConnectionManager;
import org.dom4j.DocumentException;
import org.junit.Test;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

import javax.xml.parsers.ParserConfigurationException;
import java.beans.IntrospectionException;
import java.beans.PropertyVetoException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;

public class execute {

    @Test
    public void run() throws Exception {
        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        User user = new User();

        user.setId(8);
        user.setUsername("WoW");
        IUserDao userDao = sqlSession.getMapper(IUserDao.class);
        // 查询所有用户
        System.out.println(userDao.selectList());
        // 查询单一用户
        System.out.println(userDao.selectUserById(user));
        // 删除单一用户
        userDao.deleteUser(user);
        // 更新单一用户
        userDao.updateUser(user);
        // 新增用户
        userDao.insertUser(user);
    }
}
